<template>
	<view class="userinfo">
		<view class="title">
			<view class="icon">
				<!-- <image :src="user.imgSrc" mode="" /> -->
				<image src="../../static/defaultHead.jpg" mode=""></image>
			</view>
			<view class="info">
				<view>{{ user.realname }}</view>
				<!-- <view>{{ user.subtitle }}</view> -->
			</view>
		</view>
		<!-- 信息显示 -->
		<view class="menu">
			<!-- <view class="menu_item" v-for="(item, index) in menu" :key="index">
				<image :src="item.imgSrc" mode="" />
				<view>{{ item.text }}</view>
				<view>{{ item.title }}</view>
			</view> -->
			<view class="menu_item">
				<image src="../../static/image/contactuser/userinfo/position.png" mode="" />
				<view>职务</view>
				<view>{{ user.postName ? user.postName : " " }}</view>
			</view>
			<view class="menu_item">
				<image src="../../static/image/contactuser/userinfo/role.png" mode="" />
				<view>部门</view>
				<view>{{ user.orgCodeTxt ? user.orgCodeTxt : " " }}</view>
			</view>
			<view class="menu_item">
				<image src="../../static/image/contactuser/userinfo/phone.png" mode="" />
				<view>联系方式</view>
				<view>{{ user.telephone ? user.telephone : " " }}</view>
			</view>
		</view>
		<!-- 用户操作 -->
		<view class="take">
			<view class="take_item">
				<view class="take_item1">
					<image src="../../static/image/my/take_icon1.png" mode="" />
					<view>修改密码</view>
				</view>
				<view class="take_item2">
					<image src="../../static/image/my/select.png" mode="" />
				</view>
			</view>
			<view class="take_item" @click="inspect">
				<view class="take_item1">
					<image src="../../static/image/my/take_icon2.png" mode="" />
					<view>检查更新</view>
				</view>
				<view class="take_item2">
					<view>（当前版本{{ version }}）</view>
					<image src="../../static/image/my/select.png" mode="" />
				</view>
			</view>
			<view class="take_item" @tap="ssmmSet()">
				<view class="take_item1">
					<image src="../../static/image/my/take_icon3.png" mode="" />
					<view>修改手势密码</view>
				</view>
				<view class="take_item2">
					<image src="../../static/image/my/select.png" mode="" />
				</view>
			</view>
		</view>
		<!-- 退出登录 -->
		<view class="outlogin" @tap="outLogin()">退出登录</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			version: "",
			user: {
				realname: "苏小落",
				subtitle: "城建局-办公室",
				imgSrc: "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3005228781,707351298&fm=26&gp=0.jpg",
			},
			menu: [
				{
					imgSrc: "../../static/image/contactuser/userinfo/position.png",
					text: "职务",
					title: "办公室主任",
				},
				{
					imgSrc: "../../static/image/contactuser/userinfo/role.png",
					text: "部门",
					title: "部门领导",
				},
				{
					imgSrc: "../../static/image/contactuser/userinfo/phone.png",
					text: "联系方式",
					title: "177 5971 1111",
				},
			],
			fileUrl: "",
		};
	},
	onShow() {
		console.log("plus", plus.runtime);
		console.log("plus", plus.runtime.version);
		this.version = plus.runtime.version;
		// console.log(plus.runtime.version)
		console.log(uni.getStorageSync("user_info"));
		this.user = uni.getStorageSync("user_info");
		// this.user.name = uni.getStorageSync("realname");
		// console.log(this.menu[2].title)
		// this.menu[2].title = uni.getStorageSync("userphone");
	},
	methods: {
		ssmmSet() {
			console.log("danyanji");
			uni.navigateTo({
				url: "/pages/my/gesture",
			});
		},
		inspect() {
			var _this = this;
			uni.request({
				url: "http://120.78.158.120:10085/unifysys/apkVsersion/checkversion", //请求接口
				method: "POST",
				data: {
					apkVersion: "V1.0.0", // 传入参数，版本号
					// apkVersion: 'V' + this.version, // 传入参数，版本号
				},
				success: (result) => {
					console.log(result);
					if (result.data.code == 500) {
						this.fileUrl = result.data.result;
						plus.runtime.getProperty(
							plus.runtime.appid,
							function (inf) {
								uni.showModal({
									title: "发现新版本",
									content: "确认下载更新",
									success: (res) => {
										if (res.confirm == true) {
											//当用户确定更新，执行更新
											_this.doUpData();
										}
									},
								});
							}
						);
					} else {
						uni.showModal({
							title: "暂无新版本",
							content: "当前版本为最新版",
						});
					}
				},
			});
		},
		doUpData() {
			uni.showLoading({
				title: "更新中……",
			});
			uni.downloadFile({
				//执行下载
				url: this.fileUrl, //下载地址
				success: (downloadResult) => {
					//下载成功
					uni.hideLoading();
					if (downloadResult.statusCode == 200) {
						uni.showModal({
							title: "",
							content: "更新成功，确定现在重启吗？",
							confirmText: "重启",
							confirmColor: "#EE8F57",
							success: function (res) {
								if (res.confirm == true) {
									plus.runtime.install(
										//安装
										downloadResult.tempFilePath,
										{
											force: true,
										},
										function (res) {
											utils.showToast("更新成功，重启中");
											plus.runtime.restart();
										}
									);
								}
							},
						});
					}
				},
			});
		},
		// 退出登录
		outLogin() {
			uni.removeStorageSync("token");
			uni.removeStorageSync("role");
			uni.removeStorageSync("user_info");
			uni.reLaunch({
				url: "/pages/login/index",
			});
		},
	},
};
</script>

<style lang="scss" scoped>
.userinfo {
	width: 100%;

	.title {
		width: 100%;
		height: 400rpx;
		background-image: url("../../static/image/contactuser/userinfo/userinfo_bg.png");
		background-size: 100% 100%;
		padding: 0 60rpx;
		display: flex;
		flex-flow: row nowrap;
		justify-content: flex-start;
		align-items: center;

		.icon {
			width: 172rpx;
			height: 172rpx;
			// border-radius: 50%;
			position: relative;

			image {
				width: 172rpx;
				height: 172rpx;
				border-radius: 50%;
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translateY(-50%) translateX(-50%);
			}
		}

		.info {
			margin-left: 23rpx;
			display: flex;
			flex-flow: column wrap;
			justify-content: center;

			view:nth-child(1) {
				font-size: 48rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #ffffff;
			}

			view:nth-child(2) {
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #ffffff;
				opacity: 0.6;
				margin-top: 16rpx;
			}
		}
	}

	.menu {
		width: 100%;
		display: flex;
		flex-flow: row nowrap;

		.menu_item {
			flex: 1;
			display: flex;
			flex-flow: column wrap;
			align-items: center;
			justify-content: center;

			image {
				display: block;
				width: 64rpx;
				height: 64rpx;
			}

			view:nth-child(2) {
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #8e9cb3;
				margin-top: 8rpx;
			}

			view:nth-child(3) {
				height: 30rpx;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #585f6b;
				margin-top: 24rpx;
			}

			input {
				display: block;
				color: #3074ff;
				text-align: center;
				margin-top: 24rpx;
			}
		}
	}

	.take {
		margin-top: 50rpx;
		padding: 0 40rpx;

		.take_item {
			width: 100%;
			height: 70rpx;
			display: flex;
			flex-flow: row nowrap;
			justify-content: space-between;

			.take_item1 {
				display: flex;
				flex-flow: row nowrap;
				justify-content: flex-start;
				align-items: center;

				image {
					width: 32rpx;
					height: 32rpx;
				}

				view {
					font-size: 30rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #272b32;
					margin-left: 16rpx;
				}
			}

			.take_item2 {
				display: flex;
				flex-flow: row nowrap;
				justify-content: flex-end;
				align-items: center;

				view {
					font-size: 22rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #8e9cb3;
				}

				image {
					width: 8rpx;
					height: 16rpx;
				}
			}
		}
	}

	.outlogin {
		width: 640rpx;
		height: 96rpx;
		line-height: 96rpx;
		background: rgba(248, 95, 120, 1);
		border-radius: 8rpx;
		font-size: 40rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #ffffff;
		text-align: center;
		position: fixed;
		bottom: 80rpx;
		left: 50%;
		transform: translateX(-50%);
	}
}
</style>
